<template>
	<view class="withdrawal">
		<view class="title" v-if="!incomeInfo.bankCardNo">
			<view class="title_left">
				提现至
				<view class="view1">
					<text>暂未绑定提现银行卡</text>
				</view>
			</view>
			<view class="title_right" @click="openPage('pageD','bindBank')">
				<text>去绑定</text>
				<!-- <image src="../../static/arrow2.png" class="img"></image> -->
			</view>
		</view>

		<view class="title flex" v-else>
			<view class="title_left">
				提现至
			</view>
			<view class="title_rightTow">
				<view class="view1">
					<img :src="incomeInfo.icon" class="img"></img>
					<text>{{incomeInfo.bankName}}（{{incomeInfo.bankCardNo}}）</text>
				</view>
				<view class="view2">
					提现将在24小时内到账你的绑定银行卡
				</view>
			</view>
		</view>


		<view class="content_Tow">
			<view class="main">
				<view class="view1">
					输入提现金额
				</view>
				<view class="view2">
					<span>¥</span>
					<input type="number" v-model="money" placeholder="输入提现金额" class="input" />
				</view>
				<view class="view3">
					<span>可提现余额：￥{{saleDate.amount?saleDate.amount/100:0}}元</span>
					<span @click="allWithdrawal">全部提现</span>
				</view>
			</view>
			<view class="btn1 fcc" @click="showPopup">
				<span class="text">去提现</span>
			</view>
		</view>


		<!-- 弹窗提示 -->
		<view class="mask" v-if="modalFlag" @click.stop="closeModal">
			<view class="nomral-modal">
				<view class="title">
					<span class="span1">提现金额</span>
					<span class="span2">￥{{money}}</span>
				</view>
				<view class="con">
					<view class="view1">
						<view class="left">
							提取服务费
						</view>
						<view class="right">
							¥0.5元
						</view>
					</view>
				</view>
				<view class="btnall">
					<view class="btn1" @click="onClose">取消</view>
					<view class="btn2" @click="cashOut">提现</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	var app = getApp();
	import {
		getWalletDetail,
		GetWalletInfoApi,
		GetWithdrawApi
	} from '../../apis/index.js';
	export default {
		data() {
			return {
				saleDate:{},
				incomeInfo: {
					icon: '',
					bankNumber: '',
					bankName: '招商银行',
					balance: 100
				},
				money: 0,
				modalFlag: false,
			}
		},
		onShow() {
			this.SaleDate();
		  this.GetWalletInfo();
		},
		methods: {
			SaleDate() {
				//钱包类型 1.账户余额 2.红包余额
				let that = this;
				getWalletDetail({
					walletType: 1
				}).then(res => {
					that.saleDate = res.data
					// console.log(that.saleDate,"that.saleDate")
				})
			},
			//获取银行卡信息
			GetWalletInfo() {
				GetWalletInfoApi().then(res => {
						this.incomeInfo=res.data
						// this.bankCard=res.data.bankNumber.substr(-4)
				})
			},
			// getMoney(e) {
			// 	this.money=e.detail.value
			// },
			openPage(pageBig, page) {
				uni.navigateTo({
					url: `/${pageBig}/${page}/${page}`
				})
			},
			// 全部提现
			allWithdrawal() {
				this.money = this.saleDate.amount / 100
			},
			onClose() {
				this.modalFlag = false
			},
			showPopup() {
				if (this.money < 1) {
					uni.showToast({
						title: '提现金额不能小于1元',
						icon: "none"
					})
					return;
				}

				if (this.incomeInfo&&this.incomeInfo.bankCardNo) {
					this.modalFlag = true
				} else {
					uni.showToast({
						title: '暂未绑定提现银行卡,无法提现',
						icon: 'none',
						duration: 2000
					})
				}
			},
			cashOut(e) {
				let that = this
				GetWithdrawApi({money:Number(this.money)*100}).then(res=>{
				  if(res.code==200){
				    console.log("成功成功成功")
				    this.modalFlag = false
						uni.showToast({
							title: '提现成功',
							icon: 'success',
							duration: 2000,
							success: () => {
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									});
								}, 500);
							},
						})
				    // wx.navigateTo({
				    //   url:'/pages/applyResult/applyResult?type=2'
				    // });
				  }else{
						uni.showToast({
							title: res.message,
							icon: "none",
							duration: 2000
						})
				    console.log("失败失败失败")
				  }
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f4f4f4;
	}

	.title {
		padding-top: 70rpx;
		margin: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.title_left {
			font-size: 24rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #333333;
			display: flex;
			align-items: center;

			.view1 {
				padding-left: 26rpx;
				display: flex;
				align-items: center;

				.img {
					width: 48rpx;
					height: 48rpx;
					border-radius: 50%;
				}

				text {
					font-size: 24rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #333333;
					padding-left: 13rpx;
				}
			}
		}

		.title_right {
			display: flex;
			align-items: center;
			padding-left: 30rpx;

			text {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #F43B00;
			}

			.img {
				width: 30rpx;
				height: 30rpx;
			}
		}

		.title_rightTow {
			padding-left: 30rpx;

			.view1 {
				display: flex;
				align-items: center;
			}

			text {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				padding-left: 12rpx;
			}

			.img {
				width: 40rpx;
				height: 40rpx;
			}

			.view2 {
				font-size: 20rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				margin-top: 10rpx;
			}
		}
	}

	.content_Tow {
		padding-top: 72rpx;
		margin-top: 80rpx;
		padding-bottom: 100rpx;
		width: 100%;
		min-height: 70vh;
		background: #FFFFFF;
		border-radius: 44rpx 44rpx 0rpx 0rpx;

		.main {
			margin: 0rpx 30rpx 0;

			.view1 {
				font-size: 22rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}

			.view2 {
				display: flex;
				align-items: center;
				margin-top: 50rpx;
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid rgba(239, 239, 239, 1);

				span {
					font-size: 30rpx;
				}

				.input {
					padding-left: 20rpx;
				}
			}

			.view3 {
				margin-top: 20rpx;

				span:nth-child(1) {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}

				span:nth-child(2) {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #F43B00;
					padding-left: 20rpx;
				}
			}
		}

		.btn1 {
			margin: 49rpx auto 0;
			width: 600rpx;
			height: 100rpx;
			background: #F43B00;
			border-radius: 12rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			.text {
				font-size: 28rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
			}
		}

		.prompt_Tow {
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin: 20rpx 110rpx 0;
			text-align: center;
		}
	}


	// 弹窗
	.mask {
		width: 100vw;
		height: 100vh;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;

		background-color: rgba(0, 0, 0, 0.65);

		.nomral-modal {
			text-align: center;
			width: 600rpx;
			height: 500rpx;
			overflow: hidden;
			position: absolute;
			top: 50%;
			transform: translateY(-60%);
			left: 50%;
			margin-left: -300rpx;
			background: #FFFFFF;
			border-radius: 24rpx;

			.title {
				margin: 0 30rpx;
				padding: 49rpx 0 42rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				border-bottom: 1rpx solid #EFEFEF;

				.span1 {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}

				.span2 {
					font-size: 60rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #F43B00;
				}
			}

			.con {
				margin: 0 30rpx;
				padding-top: 28rpx;

				.view1 {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}

					.right {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}
			}

			.btnall {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 64rpx 65rpx 0;

				.btn1 {
					width: 220rpx;
					height: 76rpx;
					border-radius: 12rpx;
					border: 1rpx solid #979797;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #666666;
				}

				.btn2 {
					width: 220rpx;
					height: 76rpx;
					border: 1rpx solid #F43B00;
					background: #F43B00;
					border-radius: 12rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #fff;
				}
			}
		}
	}
</style>
